<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<html>
<head>
<title>定时任务列表</title>
</head>
<body>
	<table style="width: 1000px; border: solid 1px #add9c0;" align="center"
		valign="middle">
		<tr>
			<td>job名称</td>
			<td>ip</td>
			<td>启动时间</td>
			<td>是否支持分布式</td>
			<td>job的状态</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${jobNameMap }" var="jobName">
			<tr>
				<td>${jobName.key }</td>
				<td>${jobName.value.ipStr }</td>
				<td>${jobName.value.cronStr }</td>
				<td>${jobName.value.distribute }</td>
				<td><c:choose>
						<c:when test="${jobName.value.isStart == 1}">
							启动中
						</c:when>
						<c:otherwise>
							暂停中
						</c:otherwise>
					</c:choose></td>
				<td><a href="javascript:void(0);"
					onclick="stopJob('${jobName.key}', ${jobName.value.isStart });">暂停</a>
					<a href="javascript:void(0);"
					onclick="startJob('${jobName.key}', ${jobName.value.isStart });">恢复</a>
					<a href="javascript:void(0);"
					onclick="handStartJob('${jobName.key}');">立即启动</a> <a
					href="javascript:void(0);"
					onclick="changeCronJob('${jobName.key}');">修改cron</a></td>
			</tr>
			<tr>

			</tr>
		</c:forEach>
	</table>

	<input id="contextUrl" type="hidden" value="<c:url value='/' />">
</body>
<script type="text/javascript" src="<c:url value='/js/jquery.min.js' />"></script>
<script type="text/javascript">
 	var contextUrl = $("#contextUrl").val();
	function stopJob(jobName, status) {
		if(status==0){
			alert("当前job是暂停中，不需要修改！");
			return;
		}
		window.location.href = contextUrl + "quartz/stop.do?jobName=" + jobName;
	}
	function startJob(jobName, status) {
		if(status==1){
			alert("当前job是启动中，不需要修改");
			return;
		}
		window.location.href = contextUrl + "quartz/start.do?jobName=" + jobName;
	}
	function handStartJob(jobName) {
		window.location.href = contextUrl + "quartz/handStart.do?jobName=" + jobName;
	}
	function changeCronJob(jobName) {
		var name = prompt(jobName + ":请输入更新后的cron表达式", "");
		
		if (name) {
			name = $.trim(name);
			window.location.href = contextUrl + "quartz/change_cron.do?jobName=" + jobName + "&cronExper=" + name;
		}
		
	}
</script>
</html>
